package interview;

import java.util.Scanner;

public class Solution04 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int cur = in.nextInt();
            if (cur == 0) break;
            System.out.println(calc(cur));
        }
    }

    public static int calc(int n) {
        if (n == 1) return 0;
        if (n == 2 || n == 3) return 1;
        int num1 = n / 3;
        int num2 = n % 3;
        return num1 + calc(num1 + num2);
    }
}
